package com.rockwell.sniffyHunter.test;

import com.rockwell.sniffyhunter.utils.IRobotSensors;

public class FakeRobotSensors implements IRobotSensors {

	public boolean 	m_hasLeftDistanceSensor 	= true; 
	public boolean 	m_hasFrontDistanceSensor 	= true;
	public boolean 	m_hasRightDistanceSensor	= true;
	public double 	m_leftDistance				= 0;
	public double 	m_rightDistance				= 0;
	public boolean 	m_detectFrontWall			= false;
	public int 		m_sensorFlags				= 0;
	public int[] 	m_allSensorStatus			= {0,0,0,0};
	public float 	m_orientation				= 0.0f;
	public boolean 	m_isArmUp					= false;
	public boolean 	m_isArmDown					= false;
	private int 	m_frontWallOnTimeout		= 0;
	private int 	m_leftWallOnTimeout			= 0;
	private int 	m_rightWallOnTimeout		= 0;
	
	@Override
	public boolean hasLeftDistanceSensor() {
		return m_hasLeftDistanceSensor;
	}

	@Override
	public boolean hasFrontDistanceSensor() {
		return m_hasFrontDistanceSensor;
	}

	@Override
	public boolean hasRightDistanceSensor() {
		return m_hasRightDistanceSensor;
	}

	@Override
	public double getLeftDistance() {
		return m_leftDistance;
	}

	@Override
	public double getRightDistance() {
		return m_rightDistance;
	}

	@Override
	public boolean detectFrontWall() {
		return m_detectFrontWall;
	}

	@Override
	public int[] getAllSensorStatus() {
		return m_allSensorStatus;
	}

	@Override
	public float getOrientation() {
		return m_orientation;
	}

	@Override
	public void setOrientation(float angle) {
		m_orientation = angle;
	}
	
	@Override
	public double getActiveEncoderValue() {
		// TODO Auto-generated method stub
		return 0;
	}
	
	@Override
	public int getSensorFlags() {
		int sensorFlags = m_sensorFlags;
		
		if (--m_frontWallOnTimeout > 0) {
			sensorFlags |= IRobotSensors.FRONT_SENSOR1_MASK;
		}
		if (--m_leftWallOnTimeout > 0) {
			sensorFlags |= IRobotSensors.LEFT_SENSOR1_MASK;
		}
		if (--m_rightWallOnTimeout > 0) {
			sensorFlags |= IRobotSensors.RIGHT_SENSOR1_MASK;
		}
		return sensorFlags;
	}

	@Override
	public boolean isArmUp() {
		return (m_sensorFlags & IRobotSensors.ARM_UP_SENSOR_MASK) != 0;
	}

	@Override
	public boolean isArmDown() {
		return (m_sensorFlags & IRobotSensors.ARM_DOWN_SENSOR_MASK) != 0;
	}
	
	@Override
	public boolean getFrontStatus() {
		if (m_frontWallOnTimeout > 0)
			return true;
		else
			return (m_sensorFlags & IRobotSensors.FRONT_SENSOR1_MASK) != 0;
	}

	@Override
	public boolean detectLeftWall() {
		if (m_leftWallOnTimeout > 0)
			return true;
		else
			return (m_sensorFlags & IRobotSensors.LEFT_SENSOR1_MASK) != 0;
	}

	@Override
	public boolean detectRightWall() {
		if (m_rightWallOnTimeout > 0)
			return true;
		else
			return (m_sensorFlags & IRobotSensors.RIGHT_SENSOR1_MASK) != 0;
	}

	public void setArmUp(boolean value) {
		if (value) {
			m_sensorFlags |= IRobotSensors.ARM_UP_SENSOR_MASK;
		}
		else {
			m_sensorFlags &= ~IRobotSensors.ARM_UP_SENSOR_MASK;
		}
	}
	
	public void setArmDown(boolean value) {
		if (value) {
			m_sensorFlags |= IRobotSensors.ARM_DOWN_SENSOR_MASK;
		}
		else {
			m_sensorFlags &= ~IRobotSensors.ARM_DOWN_SENSOR_MASK;
		}
	}
	
	public void setFrontWall(boolean value) {
		if (value) {
			m_sensorFlags |= IRobotSensors.FRONT_SENSOR1_MASK;
		}
		else {
			m_sensorFlags &= ~IRobotSensors.FRONT_SENSOR1_MASK;
		}
	}
	
	public void setLeftWall(boolean value) {
		if (value) {
			m_sensorFlags |= IRobotSensors.LEFT_SENSOR1_MASK;
		}
		else {
			m_sensorFlags &= ~IRobotSensors.LEFT_SENSOR1_MASK;
		}
	}
	
	public void setRightWall(boolean value) {
		if (value) {
			m_sensorFlags |= IRobotSensors.RIGHT_SENSOR1_MASK;
		}
		else {
			m_sensorFlags &= ~IRobotSensors.RIGHT_SENSOR1_MASK;
		}
	}
	
	public void setFrontWallOnTimeout(int timeout) {
		m_frontWallOnTimeout = timeout;
	}
	
	public void setLeftWallOnTimeout(int timeout) {
		m_leftWallOnTimeout = timeout;
	}
	
	public void setRightWallOnTimeout(int timeout) {
		m_rightWallOnTimeout = timeout;
	}

	@Override
	public int[] getLeftDistances() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int[] getRightDistances() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isWheelMoving() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int[] getFrontDistances() {
		// TODO Auto-generated method stub
		return null;
	}
}
